<template>
  <view class="container">
    <van-field v-model="form.title" label="标题" placeholder="请输入标题" @change="form.titlee = $event.detail"/>
    <van-field autosize v-model="form.content" label="内容" placeholder="请输入正文内容" @change="form.content = $event.detail"/>
    <van-field v-model="form.image" label="配图" placeholder="请输入图片链接" @change="form.image = $event.detail"/>
    <div style="height: 20px;"></div>
    <van-button type="primary" block @click="submitForm">发布</van-button>
  </view>
</template>

<script>
  import {
    addPost
  } from "@/api/post.js"
  
  export default {
    data() {
      return {
        form: {
          userId: 0,
          image: '',
          content: '',
          title: ''
        },
        userId: 0,
      }
    },
    created() {
      this.userId = uni.getStorageSync('userId')
    },
    methods: {
      submitForm() {
        this.form.userId = this.userId
        addPost(this.form).then(()=>{
          uni.showToast({
            title: '发布成功',
            icon: 'none',
            duration: 1000
          });
        })
      }
    }
  }
</script>

<style scoped>
  .container {
    padding: 15px;
  }

</style>
